package FulbitoFacil.Servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import FulbitoFacil.excepcion.DAOExcepcion;
import FulbitoFacil.negocio.GestionPersona;

/**
 * Servlet implementation class insertaPersona
 */
@WebServlet("/insertaPersona")
public class insertaPersona extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public insertaPersona() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		String xtipoPer = request.getParameter("tipoPer");
		String xnombres = request.getParameter("nombres");
		String xpaterno = request.getParameter("paterno");
		String xmaterno = request.getParameter("materno");
		String xsexo = request.getParameter("sexo");
		String xtipoDoc = request.getParameter("tipoDoc");
		String xnumDoc = request.getParameter("numDoc");
		String xcorreo = request.getParameter("correo");
		String xcorreoConf = request.getParameter("correoconf");
		String xpassword = request.getParameter("password");
		String xpasswordconf = request.getParameter("passwordconf");
		String xdia = request.getParameter("dia");
		String xmes = request.getParameter("mes");
		String xanio = request.getParameter("anio");
		String xfacNac = xanio + "-" + xmes + "-" + xdia;
		String xcelular = request.getParameter("celular");
		// registrar

		GestionPersona GP = new GestionPersona();
		try {
			GP.insertaPersona(xtipoPer, xnombres, xpaterno, xmaterno, xsexo,
					xtipoDoc, xnumDoc, xcorreo, xpassword, xfacNac, xcelular);
			response.sendRedirect(request.getContextPath() + "/insertaPersona");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}

	}

}
